/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit;

import picounit.features.test_finder.ObjectReloader;
import picounit.features.test_finder.ObjectReloader.Deserializer;
import picounit.features.test_instantiator.Instantiator;
import previous.picounit.TestCase;

import java.io.Serializable;

public class ObjectReloaderTest extends TestCase {
	private final Instantiator instantiator = injectCollaborator();
	private final Deserializer deserializer = injectCollaborator();

	public static class ToReload implements Serializable {
		public ClassLoader getClassLoader() {
			return getClass().getClassLoader();
		}
	}
	
	public void shouldUseClassReloaderToDeserializedClasses() {
		should.call(instantiator.instantiate(ObjectReloader.Deserializer.class))
			.andReturn(deserializer);

		ToReload deserialized = new ToReload();

		should.call(deserializer.deserialize(is.aByteArray()))
			.andReturn(deserialized);

		should.expectAboveWhenTheFollowingOccurs();

		ToReload reloaded = new ObjectReloader(instantiator).reload(new ToReload());

		assertSame(deserialized, reloaded);
	}
}
